﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="ComboPickUser.aspx.cs" Inherits="PMS.UI.BD.ComboPickUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script type="text/javascript">
        $(function () {
            var height = $("#divTotal").height();
            var master = $("#master").height();
            var content = parseFloat(height) - parseFloat(master) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script type="text/javascript">
        $(function () {
            $("#tbList").datagrid({
                url: '/Logic/BD/ComboPickAjax.aspx?method=GetComboList',
                loadMsg: '数据加载中请稍后……',
                fitColumns: true,
                pagination: true,
                rownumbers: true,
                singleSelect: true,
                idField: "ID",
                pageSize: 20,
                pageList: [20, 50, 100],
                striped: true,
                columns: [[{ field: 'ck', checkbox: true, width: 30 },
                 { field: 'ID', title: 'ID ', align: "center", width: 30 },
                 {
                     field: 'ComboName', title: '名称 ', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {
                             required: true
                         }
                     }
                 },
                  {
                      field: 'ComboType', title: 'Combo类型', sortable: true, width: 100, align: "center", editor: {
                          type: "combobox",
                          options: {
                              data: StaticCombo.ComboType,
                              valueField: 'value',
                              textField: 'text',
                              required: true
                          }
                      },
                      formatter: function (value, row, index) {
                          return com.getArrayText(StaticCombo.ComboType, value);
                      }
                  },
                 {
                     field: 'Note', title: '备注 ', align: "center", width: 250, editor: {
                         type: "validatebox",
                         options: {
                         }
                     }
                 },
                 { field: 'FillName', title: '维护人 ', align: "center", width: 100 },
               { field: 'FillDate', title: '维护时间 ', align: "center", width: 100 }]],
                onAfterEdit: function (rowIndex, rowData, changes) {

                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/BD/ComboPickAjax.aspx?method=EditCombo",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    } else if (editAction == "add") {

                        com.ajax({
                            url: "/Logic/BD/ComboPickAjax.aspx?method=AddCombo",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;
                },
                onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");

                }

            });
        });
    </script>

    <script>
        editRow = undefined;
        editAction = undefined;
        function funcAdd() {
            //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
            if (editRow == undefined) {
                $("#tbList").datagrid("insertRow", {
                    index: 0, // index start with 0
                    row: {

                    }
                });
                //将新插入的那一行开户编辑状态
                $("#tbList").datagrid("beginEdit", 0);

                //给当前编辑的行赋值
                editRow = 0;

                editAction = "add";
            }
        }
        function funcEdit() {

            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    //   var index = row.Id;
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }
        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);

        }
        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该权限吗？', function (r) {
                if (r) {
                    var rowData = $("#tbList").datagrid("getSelected");
                    console.log(rowData);
                    if (rowData) {
                        com.ajax({
                            url: '/Logic/BD/ComboPickAjax.aspx?method=RemoveCombo',
                            data: { Id: rowData.ID },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })

                            }

                        });
                    }
                }
            });
        }

        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        function funcSelectPeo() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                $.extend(com.dialogObj, { title: "分配人员", width: 500, height: 300, href: "/UI/BD/AssignComboPeoWindow.aspx" });
                $("#assignComboPeo").dialog(
                   com.dialogObj
                );
                $(top.document).find("#hidId").val(row.ID);
            }
            else {
                com.message("information", "请选中一行");
            }
        }

    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <div style="height: 100%;">

        <table id="tbList" data-options="fit:true"></table>
    </div>

    <div id="assignComboPeo">
    </div>

</asp:Content>
